﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using Royaumes_Libres.Database;
using System.Data;
using System.Data.SqlClient;
using System.Web.UI;

namespace Royaumes_Libres.Database
{
    public class cMapKingdom
    {
        public int pPosX;
        public int pPosY;
        public int pPkRace;
        public string pRace;
        public string pName;
        public int pPkKingdom;

        public cMapKingdom(string name, int pkrace, string race, int posx, int posy, int pkkingdom)
        {
            this.pName = name;
            this.pPkRace = pkrace;
            this.pRace = race;
            this.pPosX = posx;
            this.pPosY = posy;
            this.pPkKingdom = pkkingdom;
        }

        /// <summary>
        /// Retourne un array de cKingdom de tout les kingdom du monde
        /// </summary>
        /// <returns></returns>
        public static cMapKingdom[] GetAllKingdom(int PkWorld)
        {
            List<cMapKingdom> lstKingdom = new List<cMapKingdom>();
           
            SqlCommand cmd = cSQL.GetDbJeuCommand();

            cmd.Connection.Open();

            cmd.CommandText = "cde.spGetAllKingdom";
            cmd.Parameters.Add(cSQL.Param("@PkWorld", PkWorld, SqlDbType.Int));

            SqlDataReader dr = cmd.ExecuteReader();

            while (dr.Read())
            {
                lstKingdom.Add(new cMapKingdom(dr.GetString(0), dr.GetInt32(1), dr.GetString(2), dr.GetInt32(3), dr.GetInt32(4), dr.GetInt32(5)));
            }
            cmd.Connection.Close();

            return lstKingdom.ToArray();
        }

        public ucKingdomMap GetControl(Page p)
        {
            ucKingdomMap uc = (ucKingdomMap)p.LoadControl("ucKingdomMap.ascx");

            return uc;
        }
    }

}